﻿using System;
using System.Collections.Generic;
using System.Web.Caching;
using Toast.Caching;
using Toast.Core;
using Toast.Core.Interfaces;

namespace Toast
{
    public static class RequestPackageCache
    {
        public static string Insert(IEnumerable<IContent> collection)
        {
            var key = ShortGuid.NewGuid();

            HttpRuntimeCacheService.Get(key, () => collection, null, Cache.NoAbsoluteExpiration, TimeSpan.FromMinutes(20));

            return key;
        }

        public static IEnumerable<IContent> Get(string key)
        {
            var result = HttpRuntimeCacheService.Get<IEnumerable<IContent>>(key, () => { throw new Exception("Content package unavailable, may have expired."); });
            return result;
        }
    }
}